<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <span v-if="isEdit">
        <span @click="searchHistory.splice(0)">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isEdit = false">完成</span>
      </span>
      <van-icon name="delete" @click="isEdit = true" v-else />
    </van-cell>
    <van-cell :title="item" v-for="(item, index) in searchHistory" :key="index">
      <van-icon name="close" @click="historyClick(item, index)" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  props: {
    searchHistory: { type: Array },
  },
  data() {
    return {
      isEdit: false,
    };
  },
  methods: {
    historyClick(val, idx) {
      if (this.isEdit) {
        this.searchHistory.splice(idx, 1);
      } else {
        this.$emit("search", val);
      }
    },
  },
};
</script>

<style scoped lang="less"></style>